import Common from '../../common/common.js';
import UserList from './UserList.js';
import BaseWin from '../base/BaseWin.js';
import ServiceNet from '../../servicenet.js';
import Friend from './Friend.js';

/***
 * 添加好友窗口
 ***/
function AddFriendWin () {
    //人员列表对象
    this.userList = new UserList();
    BaseWin.call(this);
    this.element.className += " addFriendWin";
}

let prototype = Object.create(BaseWin.prototype);
prototype.constructor = AddFriendWin;
AddFriendWin.prototype  = prototype;

//初始化弹窗内容
AddFriendWin.prototype.initBox = function(){
    let search = Common.tool.createElement({props:{className:"searchBox"},childNodes:[
            {label:"input",tag:"input",props: {type:"text"}},
            {label:"button",tag:"button",props:{innerText:"查询"}}
        ]});
    this.element.search = search;
    this.element.win.box.appendChild(search);
    this.element.win.box.appendChild(this.userList.getElement());

    Common.tool.addHandle(search.button,"click",()=>{
         this.userList.search(search.input.value)
    });
}


/***
 * 添加好友窗口-添加备注
 ***/
function AddFriendRemarkWin (item) {
    //人员列表对象
    this.userList = new UserList();
    this.item = item;
    BaseWin.call(this);
    this.element.className += " addFriendRemarkWin";
}

let prototype2 = Object.create(BaseWin.prototype);
prototype2.constructor = AddFriendRemarkWin;
AddFriendRemarkWin.prototype  = prototype2;

AddFriendRemarkWin.prototype.initBox = function(){
    let remark =  Common.tool.createElement({props:{className:"remarkBox"},childNodes:[
            {label:"input",tag:"input",props: {type:"text"}},
            {label:"button",tag:"button",props:{innerText:"确定"}}
     ]});
    this.element.win.box.appendChild(remark);

    //添加事件
    Common.tool.addHandle(remark.button,"click",()=>{
        ServiceNet.addFriend(this.item.data.userID,remark.input.value,()=>{
            Friend.initData();
            this.item.remove();
            this.cancel();
        });
    });
}

/***
 * 查看好友详情
 ***/
function FriendInfoWin (userData) {
    this.userData = userData;
    BaseWin.call(this);
    this.element.className += " friendInfoWin";
}

let prototype3 = Object.create(BaseWin.prototype);
prototype3.constructor = FriendInfoWin;
FriendInfoWin.prototype  = prototype3;

FriendInfoWin.prototype.initBox = function(){
    let userID = this.userData.userID;
    let nick = this.userData.nick;
    let gender = this.userData.gender;
    let selfSignature = this.userData.selfSignature;

    let info = Common.tool.createElement({label:"table",childNodes:[
            {label:"tr",childNodes:[
                    {label:"th",props:{className:"tit",innerText:"ID"}},
                    {label:"td",props:{className:"text",innerText:userID}}
                ]},
            {label:"tr",childNodes:[
                    {label:"th",props:{className:"tit",innerText:"昵称"}},
                    {label:"td",props:{className:"text "+Common.tool.isNull(nick)?"grey":"",innerText:Common.tool.isNull(nick)?"暂无昵称":nick}}
                ]},
            {label:"tr",childNodes:[
                    {label:"th",props:{className:"tit",innerText:"性别"}},
                    {label:"td",props:{className:"text",innerText:gender == TIM.TYPES.GENDER_MALE?"男":(gender == TIM.TYPES.GENDER_FEMALE?"女":"未知")}}
                ]},
            {label:"tr",childNodes:[
                    {label:"th",props:{className:"tit",innerText:"签名"}},
                    {label:"td",props:{className:"text "+Common.tool.isNull(selfSignature)?"grey":"",innerText:Common.tool.isNull(selfSignature)?"暂无签名":selfSignature}}
                ]}
        ]});
    this.element.win.box.appendChild(info);
}

export {AddFriendWin,AddFriendRemarkWin,FriendInfoWin} ;
